<!DOCTYPE html>
<HTML>
<HEAD><meta name="viewport" content="width=device-width, initial-scale=1">
<Title>Simple Tree Map</Title>
<link type='text/css' rel='Stylesheet' href="maxchartapi.css" />
</HEAD>
<body bgcolor="#FFFFFF" text="#000000" topmargin="0" leftmargin="0" rightmargin="0" marginwidth="0" marginheight="0">

<p class="heading0">ChartDirector 7.0 (Java Edition)</p>
<p class="heading1">Simple Tree Map</p>
<hr class="separator">
<div class="content">
<img src="images/simpletreemap.png" width='400' height='400'>
<br><br>
This example demonstrates the basic steps in creating a tree map.<br><br>
<ul><li> Create a <a href="TreeMapChart.htm">TreeMapChart</a> object using <a href="TreeMapChart.TreeMapChart.htm">TreeMapChart.TreeMapChart</a>.<br><br>
<li> Specify the plot area of the chart using <a href="TreeMapChart.setPlotArea.htm">TreeMapChart.setPlotArea</a>.<br><br>
<li> Obtain the root node of the tree map using <a href="TreeMapChart.htm">TreeMapChart</a>,getRootNode and add child nodes to it using <a href="TreeMapNode.setData.htm">TreeMapNode.setData</a>.<br><br>
<li> Get the child node prototype using <a href="TreeMapChart.getLevelPrototype.htm">TreeMapChart.getLevelPrototype</a> and use it to configure the styles of all the child nodes.<br><br>
<li> Assign the chart to the WebChartViewer using <a href="WebChartViewer.setChart.htm">WebChartViewer.setChart</a>, and insert it to the web page using <a href="WebChartViewer.renderHTML.htm">WebChartViewer.renderHTML</a>.<br><br>
<li> Generate tool tips for the chart using <a href="BaseChart.getHTMLImageMap.htm">BaseChart.getHTMLImageMap</a>.</ul>
</div>
<p class="heading1a">Source Code Listing</p>
<div class="content">
<b>[JSP Version]</b> jspdemo/simpletreemap.jsp
<div class='codeblock'><code class='pre'>&lt;%@page import="ChartDirector.*, java.util.*" %&gt;
&lt;%
// Data for the tree map
double[] data = {25, 18, 15, 12, 8, 30, 35};

// Labels for the tree map
String[] labels = {"Alpha", "Beta", "Gamma", "Delta", "Epsilon", "Zeta", "Eta"};

// Colors for the tree map
int[] colors = {0xff5555, 0xff9933, 0xffff44, 0x66ff66, 0x44ccff, 0x6699ee, 0xdd99dd};

// Create a Tree Map object of size 400 x 400 pixels
TreeMapChart c = new TreeMapChart(400, 400);

// Set the plotarea at (10, 10) and of size 380 x 380 pixels
c.setPlotArea(10, 10, 380, 380);

// Obtain the root of the tree map, which is the entire plot area
TreeMapNode root = c.getRootNode();

// Add first level nodes to the root.
root.setData(data, labels, colors);

// Get the prototype (template) for the first level nodes.
TreeMapNode nodeConfig = c.getLevelPrototype(1);

// Set the label format for the nodes to show the label and value with 8pt Arial Bold font in black
// color (000000) and center aligned in the node.
nodeConfig.setLabelFormat("{label}&lt;*br*&gt;{value}", "Arial Bold", 8, 0x000000, Chart.Center);

// Set the node fill color to the provided color and the border color to white (ffffff)
nodeConfig.setColors(-1, 0xffffff);

// Output the chart
WebChartViewer viewer = new WebChartViewer(request, "chart1");
viewer.setChart(c, Chart.SVG);

// Include tool tip for the chart
viewer.setImageMap(c.getHTMLImageMap("", "", "title='&lt;*cdml*&gt;{label}: {value}'"));
%&gt;
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;Simple Tree Map Charts&lt;/title&gt;
    &lt;!-- Include ChartDirector Javascript Library to support chart interactions --&gt;
    &lt;script type="text/javascript" src="cdjcv.js"&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body style="margin:5px 0px 0px 5px"&gt;
    &lt;div style="font:bold 18pt verdana;"&gt;
        Simple Tree Map Charts
    &lt;/div&gt;
    &lt;hr style="border:solid 1px #000080; background:#000080" /&gt;
    &lt;div style="font:10pt verdana; margin-bottom:1.5em"&gt;
        &lt;a href="viewsource.jsp?file=&lt;%=request.getServletPath()%&gt;"&gt;View Source Code&lt;/a&gt;
    &lt;/div&gt;
    &lt;!-- ****** Here is the chart image ****** --&gt;
    &lt;%= viewer.renderHTML(response) %&gt;
&lt;/body&gt;
&lt;/html&gt;</code></div>
</div>
<br><hr class="separator"><div class="copyright">&copy; 2022 Advanced Software Engineering Limited. All rights reserved.</div>
</body>
</HTML>
